class Solution {
        /**
         *91.解码方法
         * https://leetcode.cn/problems/decode-ways/
         * @param s
         * @return
         */
        public int numDecodings(String s) {
            int n = s.length();

            //1.创建dp表
            char[] ch = s.toCharArray();
            int[] dp = new int[n + 1];

            //虚拟节点，处理边界情况
            dp[0] = 1;

            //2.初始化
            if(ch[0] != '0') dp[1] = 1;
            if(n == 1) return dp[1];

            //3.填表
            for(int i = 2;i <= n;i++){
                //单独解码
                if(ch[i-1] != '0') dp[i] += dp[i -1];

                //组合节码
                int tt = (ch[i-2] -'0') * 10 + ch[i-1] - '0';
                if(tt <= 26 && tt >= 10)
                    dp[i] +=  dp[i -2];

            }
            //4.返回
            return dp[n];
        }
}

/**
 * 不同路劲
 * https://leetcode.cn/problems/unique-paths/
 */
class Solution2{
    public int uniquePaths(int m, int n) {
        int[][] dp = new int[m + 1][n+1];
        dp[0][1] = 1;
        for(int i = 1;i <= m;i++){
            for(int j = 1;j <= n;j++){
                dp[i][j] = dp[i][j-1] + dp[i-1][j];
            }
        }
        return dp[m][n];
    }
}

/**
 * 不同路径2
 * https://leetcode.cn/problems/unique-paths-ii/
 */

class Solution3 {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int m = obstacleGrid.length;
        int n = obstacleGrid[0].length;

        int[][] dp = new int[m + 1][n+1];

        dp[0][1] = 1;
        for(int i = 1;i <= m;i++){
            for(int j = 1;j <= n;j++){
                if(obstacleGrid[i-1][j-1] == 1) dp[i][j] = 0;
                else dp[i][j] = dp[i][j-1] + dp[i-1][j];
            }
        }

        return dp[m][n];
    }
}